$import( "SmitearWebGL.Objects.Parser.Collada.DaeEntity" );

SmitearWebGL.Objects.Parser.Collada.DaeCamera = SmitearWebGL.Objects.Parser.Collada.DaeEntity.extend(
{
	/******** constructor ********/

	init : function( document, node )
	{
		this.ortho = false;
		this.fov = 0;
		this.mag = 0;
		this.aspect_ratio = 0;
		this.near = 0;
		this.far = 0;
		this.target = "";
		this.type = 0;

		this._super( document, node );
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeCamera" );
	}
	,
	read : function( node )
	{

		$THROW( node.localName == SmitearWebGL.Objects.Parser.Collada.Const.DAE_CAMERA_ELEMENT,
		"expected a '" + SmitearWebGL.Objects.Parser.Collada.Const.DAE_CAMERA_ELEMENT + "' element" );

		this._super( node );

		this.target = null;

		var children = node.childNodes;
		var numChildren = children.length;

		for( var i = 0; i < numChildren; i++ )
		{
			var child = children[i];

			switch( child.localName )
			{
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_OPTICS_ELEMENT:
					this.readOptics(child);
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_EXTRA_ELEMENT:
					this.readExtra(child);
					break;
				default:
					break;
			}
		}
	}
	,
	readOptics : function( node )
	{
		var children = node.childNodes;
		var numChildren = children.length;

		for( var i = 0; i < numChildren; i++ )
		{
			var child = children[i];

			switch( child.localName )
			{
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_TECHNIQUE_COMMON_ELEMENT:
					this.readProgramCommon(child);
					break;
				default:
					break;
			}
		}
	}
	,
	readProgramCommon : function( node )
	{
		var children = node.childNodes;
		var numChildren = children.length;

		for( var i = 0; i < numChildren; i++ )
		{
			var child = children[i];

			switch( child.localName )
			{
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_CAMERA_PERSP_ELEMENT:
					this.ortho = false;
					this.readPerspective(child);
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_CAMERA_ORTHO_ELEMENT:
					this.ortho = true;
					this.readOrthogonal(child);
					break;
				default:
					break;
			}
		}
	}
	,
	readPerspective : function( node )
	{
		var children = node.childNodes;
		var numChildren = children.length;

		for( var i = 0; i < numChildren; i++ )
		{
			var child = children[i];

			switch( child.localName )
			{
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_XFOV_CAMERA_PARAMETER:
					this.type = SmitearWebGL.Objects.Parser.Collada.TYPE_X;
					this.fov = parseFloat(this.getNodeContent(child));
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_YFOV_CAMERA_PARAMETER:
					this.type = SmitearWebGL.Objects.Parser.Collada.TYPE_Y;
					this.fov = parseFloat(this.getNodeContent(child));
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_ASPECT_CAMERA_PARAMETER:
					this.aspect_ratio = parseFloat(this.getNodeContent(child));
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_ZNEAR_CAMERA_PARAMETER:
					this.near = parseFloat(this.getNodeContent(child));
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_ZFAR_CAMERA_PARAMETER:
					this.far = parseFloat(this.getNodeContent(child));
					break;
				default:
					break;
			}
		}
	}
	,
	readOrthogonal : function( node )
	{
		var children = node.childNodes;
		var numChildren = children.length;

		for( var i = 0; i < numChildren; i++ )
		{
			var child = children[i];

			switch( child.localName )
			{
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_XMAG_CAMERA_PARAMETER:
					this.type = SmitearWebGL.Objects.Parser.Collada.TYPE_X;
					this.fov = parseFloat(this.getNodeContent(child));
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_YMAG_CAMERA_PARAMETER:
					this.type = SmitearWebGL.Objects.Parser.Collada.TYPE_Y;
					this.fov = parseFloat(this.getNodeContent(child));
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_ASPECT_CAMERA_PARAMETER:
					this.aspect_ratio = parseFloat(this.getNodeContent(child));
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_ZNEAR_CAMERA_PARAMETER:
					this.near = parseFloat(this.getNodeContent(child));
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_ZFAR_CAMERA_PARAMETER:
					this.far = parseFloat(this.getNodeContent(child));
					break;
				default:
					break;
			}
		}
	}
	,
	readExtra : function( node )
	{
		var children = node.childNodes;
		var numChildren = children.length;

		for( var i = 0; i < numChildren; i++ )
		{
			var child = children[i];

			switch( child.localName )
			{
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_TECHNIQUE_ELEMENT:
				var c = this.getNode(child, SmitearWebGL.Objects.Parser.Collada.Const.DAEMAX_TARGET_CAMERA_PARAMETER);
				if( c )
				{
					this.target = this.getNodeContent(c);
					this.target = this.target.split("#")[1];
				}
				break;
				default:
				break;
			}
		}
	}
}
);

SmitearWebGL.Objects.Parser.Collada.TYPE_X = 0;
SmitearWebGL.Objects.Parser.Collada.TYPE_Y = 1;